<template>
  <div class="coupon_index">
    <div class="center">
      <div
        class="coupon"
        :class="[
          ele.couponTemplateInfo.couponType == 1 ? 'direct' : '',
          ele.couponTemplateInfo.couponType == 2 ? 'rate' : '',
          ele.couponTemplateInfo.couponType == 3 ? 'exchange' : '',
          ele.couponTemplateInfo.couponType == 5 ? 'reduction' : '',
          ele.couponTemplateInfo.couponType == 4 ? 'carwash' : ''
        ]"
        v-for="ele in couponList"
        :key="ele.couponUserId"
      >
        <div class="left">
          <div
            class="amount"
            v-if="['1', '4', '5'].includes(ele.couponTemplateInfo.couponType)
            "
          >
            ￥
            <span class="value">{{ ele.couponTemplateInfo.couponAmt }}</span>
          </div>
          <div class="amount" v-if="ele.couponTemplateInfo.couponType == 2">
            <span class="value">{{ ele.couponTemplateInfo.couponAmt }}</span>
            %
          </div>
          <div class="condition" v-if="ele.couponTemplateInfo.couponType  == 5">
            每升立减
          </div>
          <div class="condition">
            {{
              ele.couponIssueInfo.couponThresholdAmt == 0
                ? "无门槛"
                : "满" + ele.couponIssueInfo.couponThresholdAmt + "元可用"
            }}
          </div>
          <div class="exchangeName">
            {{ ele.couponTemplateInfo.couponName }}
          </div>
        </div>
        <div class="right">
          <div class="title">
            <span class="type"
              >{{ ele.couponTemplateInfo.couponType == 1 ? "立减劵" : ""
              }}{{ ele.couponTemplateInfo.couponType == 2 ? "折扣劵" : ""
              }}{{ ele.couponTemplateInfo.couponType == 3 ? "兑换劵" : "" }}
              {{ ele.couponTemplateInfo.couponType == 4 ? "洗车劵" : "" }}
              {{ ele.couponTemplateInfo.couponType == 5 ? "立减劵" : "" }}
            </span>
          </div>
          <div
            class="content"
            :class="[ele.couponTemplateInfo.couponType != 3 ? 'notip' : '']"
            style="position: relative;"
          >
            <div class="items">
              <div
                class="item valid"
                v-if="ele.couponTemplateInfo.couponType != 3"
              >
                油品：<span>{{ ele.oils }}</span>
              </div>
              <div class="item scope">
                适用：
                <span class="hidden-scroll">
                  {{
                    ele.couponTemplateInfo.couponType == 1 ||
                    ele.couponTemplateInfo.couponType == 2 ||
                    ele.couponTemplateInfo.couponType == 4 ||
                    ele.couponTemplateInfo.couponType == 5
                      ? ele.couponStaNames
                      : ""
                  }}{{
                    ele.couponTemplateInfo.couponType == 3
                      ? ele.verStaNames
                      : ""
                  }}
                </span>
              </div>
              <div class="item valid">
                截止：<span>{{ ele.couponEffectiveTime }}</span>
              </div>
              <div class="item from">
                来源：<span>{{ ele.couponIssueInfo.issueName }}</span>
              </div>
            </div>
          </div>

          <!-- 备注提示 -->
          <div class="tip" v-if="ele.couponTemplateInfo.couponType == 3">
            {{ ele.couponTemplateInfo.couponDetails }}
          </div>
        </div>
      </div>
    </div>
    <!-- 空列表 -->
    <div
      v-if="couponList.length == 0"
      style="
        text-align: center;
        font-weight: bold;
        margin-top: 2rem;
        margin-bottom: 3rem;
      "
    >
      空空如也
    </div>

    <van-pagination
      v-show="total > 0"
      v-model="currentpage"
      :total-items="total"
      :items-per-page="queryForm.pageSize"
    />

    <div style="text-align:center">
      <van-button type="primary" style="width:90%" size="normal" @click="goback"
        >返回</van-button
      >
    </div>
  </div>
</template>

<script>
import { mapMutations, mapGetters } from "vuex";
import Vue from "vue";
import { Pagination, Icon, Checkbox, CheckboxGroup, Button } from "vant";
Vue.use(Icon);
Vue.use(Pagination);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Button);

export default {
  head() {
    return {
      title: "核销记录"
    };
  },

  data() {
    return {
      dataInfo: {},
      couponList: [],
      currentpage: 1,
      total: 0,
      queryForm: {
        pageNum: 1, //第几页
        pageSize: 100, // 容量
        enterpriseId: "",
        couponIsUsed: 1, // 0 可使用 1已使用 2已过期  3 核销记录
        mobilePhone: "",
      },
      back:null,//判断返回那个页面
      type:null,
      activeIndex:1,
      stationId:null,
    };
  },
  computed: {
    ...mapGetters({
      userInfo: "authen/userInfo"
    })
  },

  created() {
    this.dataInfo = JSON.parse(this.$route.query.dataInfo);
    this.back=this.$route.query.back||null
    this.type=this.$route.query.couponType||null
    this.activeIndex=this.$route.query.activeIndex||null
    this.stationId=this.$route.query.stationId||null
    this.getCouponList();
  },

  methods: {
    // 获取优惠券列表
    async getCouponList() {
      this.loading = true;
      const params = { ...this.queryForm };
      params.enterpriseId = this.enterpriseId;
      params.mobilePhone = this.phone;
      params.verificationTimeString = this.dataInfo.verificationTime; // 核销时间
      const res = await this.$axios.$get("/selectUserCoupons", {
        params: params
      });
      this.couponList = res.data.list || [];
      console.log("获取优惠券列表", res);

      if (res.retCode != 0) {
        alert("获取核销记录详情失败：" + res.message);
      }

      this.loading = false;
    },
    // 返回
    goback() {
      if(this.back==1){
        this.$router.go(-1)
      }else{
        window.location.href = `/${this.enterpriseId}/coupon/autoHexiao_index?couponType=${this.type}&activeIndex=${this.activeIndex}&stationId=${this.stationId}`;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.loading {
  width: 100px;
  height: 100px;
  position: fixed;
  top: 50%;
  left: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
}
.btnCheckbox {
  position: absolute;
  right: 0.2rem;
  top: 0.1rem;
  width: 0.5rem;
}
.coupon_index {
  width: 7.5rem;
  background: #ffffff;
  padding: 0 0.3rem 0 0.3rem;
  box-sizing: border-box;
  min-height: 100vh;
  margin-top: 0.3rem;

  > .top {
    width: 6.9rem;
    height: 1rem;

    .fixed {
      position: fixed;
      top: 0;
      left: 0;
      width: 7.5rem;
      height: 1rem;
      padding: 0 0.3rem 0 0.3rem;
      box-sizing: border-box;
      background: #ffffff;
      display: flex;
      justify-content: space-around;
      align-items: center;
      span {
        height: 0.45rem;
        font-size: 0.32rem;
        font-weight: 400;
        color: #aaaaaa;
        line-height: 0.45rem;
        letter-spacing: 0.01rem;
      }
      span.selected {
        color: #111111;
      }
    }
  }

  // 全选
  .checkAll {
    display: flex;
    align-items: center;
    justify-content: space-between;
    small {
      color: #666;
    }
  }
  > .center {
    .coupon {
      display: flex;
      justify-content: space-between;
      height: 2.8rem;
      margin-bottom: 0.3rem;
      box-shadow: 0rem 0rem 0.1rem 0.04rem rgba(233, 223, 223, 0.5);
      > .left {
        display: flex;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        width: 2.2rem;
        height: 2.8rem;
        text-align: center;
        .amount {
          display: block;
          font-size: 0.4rem;
          font-weight: 500;
          color: #ffffff;
          line-height: 0.56rem;
          text-align: center;
          margin-top: 0rem;
          .value {
            font-size: 0.6rem;
          }
        }
        .condition {
          font-size: 0.24rem;
          font-weight: 400;
          color: #ffffff;
          line-height: 0.33rem;
          text-align: center;
          margin-top: 0.25rem;
        }
        .exchangeName {
          display: none;
          font-size: 0.35rem;
          font-weight: 500;
          color: #ffffff;
          line-height: 0.56rem;
        }
      }
      > .right {
        width: 4.56rem;
        height: 2.45rem;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        // margin: 0.08rem 0 0.05rem 0;
        position: relative;
        padding: 0.2rem 0rem;
        box-sizing: content-box;
        .title {
          height: 0.3rem;
          font-size: 0.24rem;
          font-weight: 600;
          line-height: 0.33rem;
          .type {
            width: 1.13rem;
            height: 0.3rem;
            line-height: 0.3rem;
            display: inline-block;
            background: #bfbfbf !important;
            border-radius: 0.19rem;
            font-size: 0.24rem;
            font-weight: 600;
            color: #ffffff;
            text-align: center;
          }
          .state {
            margin-left: 0.2rem;
            color: #7f7f7f;

            height: 0.33rem;
            font-size: 0.24rem;
            font-weight: 600;
            line-height: 0.33rem;
          }
        }
        .content {
          display: flex;
          justify-content: space-between;
          margin: 0.05rem 0 0.05rem 0;
          height: 1.4rem;

          .items {
            width: 4.3rem;
            height: 100%;
            display: flex;
            justify-content: space-around;
            flex-direction: column;
            .item {
              color: #272626;
              font-size: 0.21rem;
              > span {
                width: 3.3rem;
                display: inline-block;
                color: #272626;
                font-size: 0.22rem;
                font-weight: bold;
                overflow: scroll; /* 超出部分隐藏 */
                white-space: nowrap; /* 文本不换行 */
              }
            }
            .from {
              display: block;
            }
          }
          > .btn {
            display: flex;
            flex-direction: column;
            justify-content: center;
            margin-right: 0.1rem;
            > button {
              height: 0.6rem;
              background: linear-gradient(143deg, #fad965 0%, #f3b235 100%);
              border-radius: 0.2rem;
              border: none;
              outline: none;
              color: #ffffff;
              line-height: 0.33rem;
              font-size: 0.3rem;
              font-weight: 400;
              overflow: hidden; /* 超出部分隐藏 */
              white-space: nowrap; /* 文本不换行 */
              display: none;
            }
          }
        }
        .notip {
          height: 1.8rem;
        }
        .tip {
          margin-right: 0.2rem;
          border-top: 0.02rem dashed #d8d8d8;
          height: 0.49rem;
          font-size: 0.22rem;
          font-weight: 400;
          color: #7f7f7f;
          line-height: 0.23rem;
          padding-top: 0.12rem;
          box-sizing: border-box;
          overflow: scroll; /* 超出部分隐藏 */
          white-space: nowrap;
          /*  text-overflow: ellipsis;*/
        }
      }
    }
    .grey {
      background-color: #eee !important;
    }
    .carwash {
      > .left {
        background: url("../../../static/coupon/quan4.2x.png") no-repeat;
        background-size: 100% 100%;
      }

      > .right {
        > .title > .type {
          background: #19c79b;
        }

        > .content > .btn button {
          background: linear-gradient(143deg, #21d9b4 0%, #0fb582 100%);
          display: block;
        }
      }
    }
    .reduction {
      > .left {
        background: url("../../../static/coupon/lijian.png") no-repeat;
        background-size: 100% 100%;
      }

      > .right {
        > .title > .type {
          background: #eb6ba4;
        }

        > .content > .btn button {
          background: linear-gradient(143deg, #e986b2 0%, #ee559a 100%);
          display: block;
        }
      }
    }

    .direct {
      > .left {
        background: url("../../../static/coupon/quan4.2x.png") no-repeat;
        background-size: 100% 100%;
      }
      > .right {
        > .title > .type {
          background: #f8ce57;
        }
        > .content > .btn button {
          background: linear-gradient(143deg, #fad965 0%, #f3b235 100%);
        }
      }
    }
    .rate {
      > .left {
        background: url("../../../static/coupon/quan4.2x.png") no-repeat;
        background-size: 100% 100%;
      }
      > .right {
        > .title > .type {
          background: #eb8573;
        }
        > .content > .btn button {
          background: linear-gradient(143deg, #f4a796 0%, #e67462 100%);
        }
      }
    }
    .exchange {
      > .left {
        background: url("../../../static/coupon/quan4.2x.png") no-repeat;
        background-size: 100% 100%;
        > .amount,
        > .condition {
          display: none;
        }
        > .exchangeName {
          display: inline-block;
          width: 1.5rem;
          margin: 0 auto;
        }
      }
      > .right {
        > .title > .type {
          background: #19c79b;
        }
        > .content {
          > .items {
            width: 3.3rem;
            .item span {
              width: 2.3rem;
            }
          }
          > .btn button {
            background: linear-gradient(143deg, #21d9b4 0%, #0fb582 100%);
            display: block;
          }
        }
      }
    }
    .expired {
      > .left {
        background: url("../../../static/coupon/quan4.2x.png") no-repeat;
        background-size: 100% 100%;
      }
      > .right {
        > .title > .type {
          background: #bfbfbf;
        }
        > .content > .btn button {
          display: none;
        }
      }
    }
  }
  > .bottom {
    margin-top: 0.8rem;
    margin-bottom: 0.3rem;
    text-align: center;
    font-size: 0.22rem;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.25);
    line-height: 0.32rem;
    letter-spacing: 1px;
  }

  .sbuBtn {
    position: fixed;
    bottom: 1px;
    width: 100%;
    left: 0;
    text-align: center;
    button {
      width: 80%;
    }
  }
}
.hidden-scroll::-webkit-scrollbar {
  display: none;
}
</style>
